#include "Humain.h"
using namespace std;

const unsigned int Humain::taille = 4;

const ListCapa Humain::Liste[4] = {
  {"Agressivité"      ,  5},
  {"PV supplémentaire", 10},
  {"Portes secrètes"  , 10},
  {"Solidité"         ,  5}
};

Humain::Humain(vector<unsigned int> cap)
  :Race("Humain")
{
  for (unsigned int i(0); i < cap.size(); i++)
    capacites.push_back(cap[i]);
}

Humain::Humain(unsigned int& PP)
  :Race("Humain")
{
  dout(BLANK) << setfill('*') << setw(56) << '*' << endl;
  dout(BLANK) << "Création d'un humain" << endl << endl;
  unsigned int nbr(0);
  bool test(true), deja_pris, encore(false);
  PP = 10;
  do
    {
      dout(BLANK) << "Tu as " << PP << " pp à dépenser" << endl;
      for (unsigned int i(0); i < taille; i++)
	dout(BLANK) << i+1 << ' ' << (Liste[i].Capa)
		    << " (" << Liste[i].Cout << " pp)" << endl;
      dout(BLANK) << taille + 1 << " Aucune" << endl;
      dout(BLANK) << "Choisir les capacités raciales" << endl;
      while(test)
	{
	  nbr = demander_unsigned_borne("("+write_int(PP)+" pp restants) ",
					1, taille + 1);
	  if (nbr != taille + 1)
	    {
	      if (PP >= Liste[nbr-1].Cout)
		{
		  deja_pris = safe_push_back(&capacites, nbr - 1);
		  if (deja_pris)
		    dout(WARN) << "Déjà sélectionné" << endl;
		  else
		    {
		      PP -= Liste[nbr-1].Cout;
		      capacites.push_back(nbr-1);
		      dout(BLANK) << "Capacité choisie : "
				  << (Liste[nbr-1].Capa) << endl;
		    }
		}
	      else
		dout(BLANK) << "Pas assez de pp" << endl;
	    }
	  else
	    test = false;
	}
      
      affiche_info();
      dout(BLANK) << endl <<  "1 pour continuer, 2 pour recommencer" << endl;
      nbr = demander_unsigned_borne("Choix ", 1, 2);
      if (nbr == 2)
	{
	  PP = 10;
	  capacites.clear();
	  test = true;
	  encore = true;
	  dout(BLANK) << endl;
	}
      else
	encore = false;
    }
  while(encore);

  dout(BLANK) << endl << setfill('*') << setw(56) << '*' << endl;
}

Humain::~Humain()
{}

void Humain::appliquer_ajustements(unsigned int tab[6])
{}

void Humain::affiche_info()
{
  dout(BLANK) << "Race : " << Type << endl;
  for (unsigned int i(0); i<capacites.size(); i++)
    dout(BLANK) << (Liste[capacites[i]].Capa) << endl;
}

string Humain::get_capacite(const unsigned int& i) const
{
  return (Liste[get_capa(i)].Capa);
}
